package com.example.virgaonline;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class Settings extends Activity{
	final LevelOneActivity game = new LevelOneActivity();
	
	@Override
	protected void onCreate(Bundle savedInstanceState){
		setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_settings);
		
		TextView music = (TextView) findViewById(R.id.music);
		TextView sound = (TextView) findViewById(R.id.sound);
		TextView volume = (TextView) findViewById(R.id.volume);
		final TextView finalvolume = (TextView) findViewById(R.id.finalvolume);
		
		
		// 
		// SEEKBAR FOR VOLUME
		//
		SeekBar sbvolume = (SeekBar) findViewById(R.id.sbvolume);
		sbvolume.setProgress(100);
		volume.setText(100);
		
		sbvolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
			@Override
			public void onProgressChanged(SeekBar sbvolume, int progress, boolean value){
				float vol = (float) progress / 100;
				game.setMusicVolume(vol); // need to implement this in LevelOneActivity
				finalvolume.setText(progress);
			}

			@Override
			public void onStartTrackingTouch(SeekBar arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onStopTrackingTouch(SeekBar arg0) {
				// TODO Auto-generated method stub
				
			}
		});
		
		
		// 
		// Toggling sound
		//
		
		final ToggleButton toggleSound = (ToggleButton) findViewById(R.id.toggleSound);
		toggleSound.toggle();
		game.toggleSounds(true);
		toggleSound.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View view){
				if(toggleSound.isChecked()){
					Toast.makeText(Settings.this, "Sound: ON", Toast.LENGTH_SHORT).show();
					game.toggleSounds(true);
				}else{
					Toast.makeText(Settings.this, "Sound: OFF", Toast.LENGTH_SHORT).show();
					game.toggleSounds(false); 
				}
			}
		});
		
		//
		// Toggling music
		//
		
		final ToggleButton toggleMusic = (ToggleButton) findViewById(R.id.toggleMusic);
		toggleSound.toggle();
		game.toggleMusic(true);
		toggleSound.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View view){
				if(toggleSound.isChecked()){
					Toast.makeText(Settings.this, "Music: ON", Toast.LENGTH_SHORT).show();
					game.toggleMusic(true);
				}else{
					Toast.makeText(Settings.this, "Music: OFF", Toast.LENGTH_SHORT).show();
					game.toggleMusic(false); 
				}
			}
		});
		
		//
		// Saving settings with a button
		//
		
		Button savebutton = (Button) findViewById(R.id.savebutton);
		savebutton.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View view){
				StartMenu.areSettingsChanged();
				Toast.makeText(Settings.this, "Saved", Toast.LENGTH_SHORT).show();
				Intent gotoStartMenu = new Intent(Settings.this, StartMenu.class);
				startActivity(gotoStartMenu);
				finish();
			}
		});
	}
	
	
}
